using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;

public class JumpTrigger : MonoBehaviour
{
    [Header("跳跃目标点A")]
    public Transform pointA;
    [Header("跳跃目标点B")]
    public Transform pointB;

    void OnTriggerEnter2D(Collider2D collision)
    {
        // 动画
        this.Core(collision, true);
        // 位移
        var distanceA = Vector2.Distance(pointA.position, collision.transform.position);
        var distanceB = Vector2.Distance(pointB.position, collision.transform.position);
        var targetDistance = distanceA > distanceB ? pointA : pointB;
        collision.transform.DOMove(targetDistance.position, 0.5f);
        // collision.transform.position = targetDistance.position;
    }

    void OnTriggerExit2D(Collider2D collision)
    {
        this.Core(collision, false);
    }
    
    private void Core(Collider2D collision, bool value)
    {
        if (collision.CompareTag(Defines.MainCharacterName))
        {
            collision.GetComponent<LunaController>().Jump(value);
        }
    }
}
